// 封装所有用户的请求
import request from '@/utils/request.js'

// 发送登录请求
export const login = data => {
  return request({
    method: 'POST',
    url: '/v1_0/authorizations',
    data
  })
}
// 发送验证码请求
export const sendCode = mobile => {
  return request({
    method: 'GET',
    url: '/v1_0/sms/codes/' + mobile
  })
}
// 获取用户个人资料请求
export const getUserProfile = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user'
  })
}
// 获取用户频道列表
export const getUserChannels = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/channels'
  })
}
// 取关请求
export const deleteUserFailure = Id => {
  return request({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + Id
  })
}

// 关注请求
export const addUserFailure = Id => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target: Id
    }
  })
}

// 获取用户个人信息
export const getUserInfo = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/profile'
  })
}

// 修改用户昵称
export const setUserProfile = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/profile',
    data
  })
}

// 修改用户头像
export const saveAvatar = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data
  })
}

// 刷新用户token
export const getToken = () => {
  return request({
    method: 'PUT',
    url: '/v1_0/authorizations'
  })
}
